package com.yihu.wlyy.web.quota;

import com.yihu.wlyy.job.*;
import com.yihu.wlyy.service.quota.JobService;
import com.yihu.wlyy.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2016/8/15.
 * 任务启动
 */
@Controller
@RequestMapping("/job")
public class JobController extends BaseController {
    @Autowired
    private JobService jobService;
    /**
     * 启动任务
     *
     * @param id id
     * @return
     */
    @RequestMapping(value = "startNowById")
    @ResponseBody
    public String startNowById(String id) {
        try {
            jobService.startNowById(id);
            return success("启动成功！");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
        }
    }

    /**
     * 生成过去几天的数据
     * @param day
     * @return
     */
    @RequestMapping(value = "productDataByDay")
    @ResponseBody
    public String productDataByDay(Integer day) {
        try {
            jobService.productDataByDay(day);
            return success("启动成功！");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
        }
    }

    /**
     * 生成过去某一天的全部的数据
     * @param day
     * @return
     */
    @RequestMapping(value = "productDataByOneDay")
    @ResponseBody
    public String productDataByOneDay(String day) {
        try {
            jobService.productDataByOneDay(day);
            return success("启动成功！");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
        }
    }

    /**
     * 生成过去某一天的某一个指标的数据
     * @param day
     * @return
     */
    @RequestMapping(value = "productDataByOneDayWithId")
    @ResponseBody
    public String productDataByOneDayWithId(String day,String id) {
        try {
            jobService.productDataByOneDayWithId(day,id);
            return success("启动成功！");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
        }
    }

    /**
     * 启动任务
     *
     * @param id id
     * @return
     */
    @RequestMapping(value = "startById")
    @ResponseBody
    public String startById(String id) {
        try {

            jobService.startById(id);
            return success("启动成功！");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
        }
    }
    /**
     * 停止任务
     *
     * @param id id
     * @return
     */
    @RequestMapping(value = "stopById")
    @ResponseBody
    public String stopById(String id) {
        try {
            jobService.stopById(id);
            return success("停止成功！");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
        }
    }

    /**
     * 停止所有任务
     *
     * @return
     */
    @RequestMapping(value = "stopAll")
    @ResponseBody
    public String stopAll() {
        try {
            jobService.stopAll();
            return success("停止成功！");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
        }
    }

    /**
     * 启动所有任务
     *
     * @return
     */
    @RequestMapping(value = "startAll")
    @ResponseBody
    public String startAll() {
        try {
            jobService.startAll();
            return success("启动成功！");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
        }
    }

    @RequestMapping(value = "startaaaa")
    @ResponseBody
    public String startaaaa() {
        try {
            jobService.startaaaa();
            return success("启动成功！");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:"+e.getMessage());
        }
    }
}
